<template>
  <h1 style="text-align: left;">图标的大小和颜色由父节点的font-size和color样式决定。(双击可复制)</h1>
  <div class="icon-box">
    <div v-for="(item, index) in icons" @dblclick="copy(item.name)" :key="index"
      style="user-select: none;margin: 40px;cursor: pointer;font-size: 30px;" :style="{ color: getColor() }"
      title="双击复制">
      <component :is="item" />
      <div style="margin-top: 10px;font-size: 14px;"> {{ `
        <${item.name} />` }}
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import icons from "../packages/components";
//随机颜色
const getColor = () => {
  const letters = '0123456789ABCDEF';
  let color = '#';
  for (let i = 0; i < 6; i++) {
    color += letters[Math.floor(Math.random() * 16)];
  }
  return color;
}

const copy = (name?: string) => {
  navigator.clipboard.writeText(name ?? '').then(() => {
    // console.log('Text copied to clipboard');
    alert('已成功复制：' + (name ?? ''));
  }, (error) => {
    console.error('Error copying text: ', error);
  });
}

</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 10px;
}

.es-icon-loading {
  animation: identifier 1.5s infinite linear;
}

@keyframes identifier {
  0% {
    transform: rotate(0deg);
  }

  20% {
    transform: rotate(72deg);
  }

  40% {
    transform: rotate(144deg);
  }

  60% {
    transform: rotate(216deg);
  }

  80% {
    transform: rotate(288deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.icon-box {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
}
</style>
